﻿using Network.Utils;
using ProtoBuf;

[ProtoContract]
public class UserData
{
    public static int OnlineTimeout = 40;

    [ProtoMember(1)] public uint id;         // 使用SessionId作为userId
    [ProtoMember(2)] public string account;  // 使用deviceName作为账号

    public UserServerData svrdata = new UserServerData();

    public override string ToString()
    {
        return string.Format("<id:{0}, name:{1}, online:{2}>", id, account, svrdata.online);
    }
}

public class UserServerData
{
    public uint lastHeartBeatTime = 0;
    private bool _online = false;
    public bool online
    {
        get
        {
            if (_online)
            {
                uint dt = (uint)TimeUtils.GetTotalSecondsSince1970() - lastHeartBeatTime;
                if (dt > UserData.OnlineTimeout)
                {
                    _online = false;
                }
            }
            return _online;
        }
        set { _online = value; }
    }
}